package SV_STRBUF_CLEAN;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Example_02 {
    private Connection con;
    private void processingData(String user) throws SQLException {
        String credential = getCredential(user);
        // ...

    }

    private String getCredential(String user) throws SQLException {
        Statement statement = con.createStatement();
        StringBuffer buffer = new StringBuffer();
        try {
            ResultSet resultSet = statement.executeQuery("SELECT * FROM credentials WHERE name='" + user + '\'');
            while (resultSet.next()) {
                String key = resultSet.getString("key");
                buffer.append(key);
            }

            final String result = buffer.toString();
            return result;
        } finally {
            buffer.delete(0, buffer.length());
            statement.close();
        }
    }
}
